<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>设置人员权重 </span>
      <el-tooltip class="item" effect="dark" content="权重值越大越优先，权重值为空不会被分配数据" placement="right">
        <i class="el-icon-warning-outline" style="color: #409eff"></i>
      </el-tooltip>
    </div>
    <div class="text item" v-loading="loadingQuan">
      <el-form ref="form" :inline="true" label-width="80px">
        <el-form-item v-for="(item,i) in QuanArr" :key="item.wUserId" :label="item.name">
          <el-input type="number" v-model="item.orderNum" placeholder="请输入权重值"></el-input>
        </el-form-item>
        <el-row style="text-align: center">
          <el-form-item>
            <el-button type="primary" @click="getDataQuanSub">保存</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
  </el-card>
</template>

<script>
import { RootIndexQuanInit, RootIndexQuanSub } from '../../../../api/index';
export default {
  data() {
    return {
      loadingQuan: true,
      QuanArr: [],
    };
  },
  created() {
    this.getDataQuanInit();
  },
  watch: {
    $route: 'getDataQuanInit',
  },
  methods: {
    //获取公海初始化数据
    getDataQuanInit() {
      RootIndexQuanInit().then((res) => {
        this.loadingQuan = false;
        if (res.code === 0) {
          res.userList.forEach((item, i) => {
            this.QuanArr.push({
              name: item.name,
              wUserId: item.id,
              orderNum: item.weightOrderNum
            })
          })
        } else {
          this.$message(res.msg);
        }
      });
    },
    //提交公海设置
    getDataQuanSub() {
      this.loadingQuan = true;
      let arr = [];
      this.QuanArr.forEach((item, i) => {
        arr.push({
          wUserId: item.wUserId,
          orderNum: item.orderNum,
        })
      })
      RootIndexQuanSub({ weightList: arr, type: '0' }).then((res) => {
        this.loadingQuan = false;
        if (res.code === 0) {
          this.$message.success("设置成功");
        } else {
          this.$message(res.msg);
        }
      });
    },
  }
};
</script>

<style scoped>
.box-card {
    margin-bottom: 20px;
}
.mar-10 {
    margin-bottom: 10px;
}
</style>
